﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;

namespace SindSaudeCamadas.Dados
{
    public class publicacoes
    {
        Conex conexao = new Conex();
        public DataTable carregaPublicacoes()
        {
            DataTable dt = new DataTable();
            MySqlCommand cmdSQL = new MySqlCommand();
            MySqlDataAdapter daSQL = new MySqlDataAdapter();
            try
            {
                string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                cmdSQL.Connection = conexao.retornaConexao(conex);

                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandText = "select * from tbpublicacoes;";

                cmdSQL.Connection.Open();
                daSQL.SelectCommand = cmdSQL;
                daSQL.Fill(dt);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmdSQL.Connection.Dispose();
                cmdSQL.Dispose();
                daSQL.Dispose();
            }
            return dt;
        }
        public bool insereAcordos(string strCaminho, string strNome,int intAno)
        {
            bool insere = false;
            DataTable dt = new DataTable();
            MySqlCommand cmdSQL = new MySqlCommand();
            try
            {
                string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                cmdSQL.Connection = conexao.retornaConexao(conex);

                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandText = "insert into tbpublicacoes(strCaminho,strNome,datArquivo,intStatu,Ano)values(@strCaminho,@strNome,now(),0,@Ano);";
                cmdSQL.Parameters.AddWithValue("@strCaminho", strCaminho);
                cmdSQL.Parameters.AddWithValue("@strNome", strNome);
                cmdSQL.Parameters.AddWithValue("@Ano", intAno);
                cmdSQL.Connection.Open();
                cmdSQL.ExecuteNonQuery();
                insere = true;
            }
            catch (Exception)
            {
                insere = false;
            }
            finally
            {
                cmdSQL.Connection.Dispose();
                cmdSQL.Dispose();
            }
            return insere;
        }
    
    }
}
